package reflect1;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Test3 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, NoSuchFieldException {
        Class<?> clazz = Class.forName("reflect1.Stu");
        Method[] declaredMethods = clazz.getDeclaredMethods();
        for (Method declaredMethod : declaredMethods) {
            System.out.println(declaredMethod);
        }

        Method setName = clazz.getMethod("setName", String.class);
        System.out.println(setName);

        System.out.println(setName.getName());

        Class<?>[] exceptionTypes = setName.getExceptionTypes();
        for (Class<?> exceptionType : exceptionTypes) {
            System.out.println(exceptionType);
        }

        Stu stu = new Stu("aaa");
        setName.invoke(stu, "bbb");
        System.out.println(stu);

    }
}
